// import { Navigate } from "react-router-dom";
// import { isAuth } from "@/utils";
// const AuthRoute = (element) => {
//   return (
//     <>{isAuth() ? element : <Navigate to="/" replace={true}></Navigate>}</>
//   );
// };
// export default AuthRoute;
import { useLocation, Navigate } from "react-router-dom";
import { isAuth } from "@/utils";
import { useDispatch } from "react-redux";
import { setLocation } from "@/store/modules/login";
// import { useEffect } from "react";

const AuthRoute = ({ element }) => {
  // console.log(element);
  console.log(isAuth());
  // const navigate = useNavigate();
  const dispatch = useDispatch();
  // const location = useLocation;
  const location = useLocation();
  console.log(location);
  dispatch(setLocation(location.pathname));

  return isAuth() ? element : <Navigate to="/" replace={true} />;
};
export default AuthRoute;
